package own.stu.jobgib.playown.tools.easyRandom;

import lombok.Data;
import org.jeasy.random.EasyRandom;
import org.jeasy.random.EasyRandomParameters;

import java.nio.charset.Charset;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;

/**
 * 核心在于多种类型的 randomizerRegister ,每个类型的register包含 类似的randomizer , Map<Class, Randomizer>
 * <p>
 * 通过反射类注入属性值
 *
 */
public class EasyRandomTest {

    public static void main(String[] args) {

        EasyRandomParameters randomParameters = new EasyRandomParameters()
                .seed(100)
                .objectPoolSize(10)
                .charset(Charset.defaultCharset())
                .dateRange(LocalDate.now(), LocalDate.now().plus(1, ChronoUnit.DAYS))
                .stringLengthRange(5, 8)
                .collectionSizeRange(2, 4)
                .randomize(String.class, () -> "ni mei de")
                .scanClasspathForConcreteTypes(true)
                .overrideDefaultInitialization(false)
                .ignoreRandomizationErrors(true);

        EasyRandom easyRandom = new EasyRandom(randomParameters);

        Person person = easyRandom.nextObject(Person.class);
        System.out.println(person);

        List<Person> persons = new ArrayList<>();
        easyRandom.objects(Person.class, 5).forEach(v -> {
            persons.add(v);
        });
        System.out.println(persons);


    }

    @Data
    public static class Person {

        String name;
        int sex;
        int age;
    }
}
